package com.youdoneed.common.service;

import com.google.gson.Gson;
import com.youdoneed.base.common.OkHttpUtils;
import com.youdoneed.common.model.CheckImageResult;
import okhttp3.FormBody;
import okhttp3.Request;
import okhttp3.RequestBody;

/**
 * 检查图片是否涉黄涉暴。
 */
public class CheckImage {

    private static final String HOST = "http://imgaudit.market.alicloudapi.com/greenImg";
    private static final String APPCODE = "b2fb6bdaf3fb48a8a5843a9090d16a9c";

    // GSON是线程安全的 可以共享
    private static final Gson GSON = new Gson();

    public static class ApiResult {
        public String showapi_res_code;
        public String showapi_res_error;
        public CheckImageResult showapi_res_body;
    }

    /**
     * 检查图片是否涉黄涉暴。
     */
    public static CheckImageResult checkImage(String imgUrl) {

        ApiResult apiResult = OkHttpUtils.formPost(HOST)
                .param("imgUrl", imgUrl).param("type", "1")
                .header("Authorization", "APPCODE " + APPCODE)
                .callJsonObject(ApiResult.class);

        return apiResult.showapi_res_body;
    }

}
